﻿using Apps.Model.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Apps.Repository
{
    public class SqlDbContext : DbContext
    {
        //public SqlDbContext(DbContextOptions options) : base(options)
        //{

        //}

        public SqlDbContext(DbContextOptions<SqlDbContext> options) : base(options)
        {
        }
        //protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        //{
        //    optionsBuilder.UseSqlServer("Server=.;Database=EFDemo;User Id=sa;Password=Liang251147;TrustServerCertificate=True;");
        //}




        public DbSet<SysMenu> Menus { get; set; }

        public DbSet<SysRoleMenu> RoleMenu { get; set; }
        public DbSet<SysUserRole> UserRole { get; set; }
        public DbSet<SysLogininFor> LogininFor { get; set; }
        public DbSet<SysRole> Roles { get; set; }

        public DbSet<SysUser> Users { get; set; }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {

            //设置主键
            modelBuilder.Entity<SysUserRole>() 
             .HasIndex(e => new { e.UserId, e.RoleId })
             .IsUnique();
        }
    }
}